package UI;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;


/**
 * This class make to {@link MessageBox} jump when we got an invalid operation from the user.
 * The class gets the error by {@link String}. 
 * @author DROR
 */
public class ErrorMassage {

	/**
	 * Constructor
	 */
	public ErrorMassage(final String error) 
	{
		/* create a new thread for each error massage */
		Thread thread = new Thread() {  
			public void run() {
				OurGUI.display.asyncExec(new Runnable() {
					public void run() 
					{
						MessageBox messageBox;
						if (error.equals("No matching file"))          		
							messageBox = new MessageBox(new Shell(OurGUI.display),SWT.ICON_INFORMATION |SWT.OK);
						else
						{
							messageBox = new MessageBox(new Shell(OurGUI.display),SWT.ICON_ERROR |SWT.OK);
							messageBox.setText("Error");
						}
						/* showing the relevant error massage */
						messageBox.setMessage(error); 
						int response = messageBox.open();
						if (response == SWT.YES)
							System.exit(0);
					}
				});
			}
		};
		thread.start();
	}
}
